layui.use(['layer', 'carousel','form'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var carousel = layui.carousel;
    var device = layui.device;
    var form = layui.form;
    var buttomId = "全局变量";

    /**
     * 系统管理--用户管理
     */
    var MgrUser = {
        tableId: "userTable",    //表格id
        condition: {
            name: "",
            deptId: "",
            timeLimit: ""
        }
    };

    // 渲染轮播
    carousel.render({
        elem: '.layui-carousel',
        width: '100%',
        height: '60px',
        arrow: 'none',
        autoplay: true,
        trigger: device.ios || device.android ? 'click' : 'hover',
        anim: 'fade'
    });




    $(function () {



        //点击+ 创建框架
        $('#schedule_frame_create').on('click', function(){
            layer.open({
                type:2,
                area: ['800px', '500px'],
                title: '添加日程框架',
                content: Feng.ctxPath + '/myScheduleFrame/addSframe',
                tableId: MgrUser.tableId
            });
        });


        /*点击日程框架栏的更多*/
        $("#schedule_frame_more").click(function () {
            Feng.success("正在跳转到日程框架页面");
            window.location.href="/myScheduleFrame/showMyScheduleFrame";
        });


        /*点击日程表栏的更多*/
        $("#my_schedule_more").click(function () {
            Feng.success("正在跳转到日程表页面");
            window.location.href="/myScheduleForm/showScheduleForm";
        });

        $("#my_schedule_create").click(function () {
            layer.open({
                type:2,
                area: ['800px', '400px'],
                title: '选择日程框架并创建日程表',
                content: Feng.ctxPath + '/myScheduleFrame/selectframe',
                tableId: MgrUser.tableId
            });
        });


        //加载页面信息
        $.post({
            url:"/mySchedule/myFirst",
            success:function (json) {

                var scheduleForms =json.scheduleForms;
                var scheduleFrames=json.scheduleFrames;
                var scheduleFormItems=json.scheduleFormItems;

                //用于sform拼接
                var form="";
                //用于sframe拼接
                var frame="";
                //用于今日日程拼接
                var sformItemHtml="";

                var sformStatus="checked";
                var sframeStatus="checked";
                var publish='off';

                for (var i=0;i<scheduleForms.length;i++) {
                    var creatTime=createTime(scheduleForms[i].creatTime);

                    if (scheduleForms[i].isShare!="on"){
                        sformStatus="";

                    }
                   form+="<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md3 \" id=\"show-btn\">\n" +
                       "    <div class=\"layui-card layui-height-lwh\" id=\"show1\">\n" +
                       "        <div class=\"box layui-card-background-lwho\">\n" +
                       "            <div class=\"box-content\">\n" +
                       "                <div class=\"layui-card-header layui-height-lwh-header\">\n" +"" +
                       "                <input type=\"text\" id='selectId' value='"+scheduleForms[i].sformId+"' hidden />"+
                       "                    <label>创建时间："+creatTime+"</label>\n" +
                       "                </div>\n" +
                       "                <div class=\"layui-card-body layui-height-lwh-body\">\n" +
                       "                    <p class=\"lay-big-font\">"+scheduleForms[i].sformName+"</p>\n" +
                       "                    <p><span class=\"pull-right\">\n" +
                       "                                                  <input type=\"checkbox\" name=\"my_schedule_open_1\" lay-filter=\"myfirst_share\"\n" +
                       "                                                         id='"+scheduleForms[i].sformId+" ' lay-skin='switch' lay-text=\"公开|私有\" "+sformStatus+" ></span></p>\n" +
                       "                </div>\n" +
                       "                <ul   class=\"icon\">\n" +
                       "                    <li >\n" +
                       "                        <a  lay-filter='updateBtn' href='javaScript:openRevise("+scheduleForms[i].sformId+")' > <i class=\"fa fa-magic\"></i></a>\n" +
                       "                    </li>\n" +
                       "                    <li>\n" +
                       "                        <a href='/myScheduleForm/checkScheduleForm?sformId="+scheduleForms[i].sformId+"'  id='check'><i class=\"fa fa-check\"></i></a>\n" +
                       "                    </li>\n" +
                       "                    <li>\n" +
                       "                        <a  id='combine' href='javaScript:combineSform("+scheduleForms[i].sformId+")'  ><i class=\"fa fa-legal\"></i></a>\n" +
                       "                    </li>\n" +
                       "                    <li>\n" +
                       "                        <a  id='remove"+scheduleForms[i].sformId+"'href='javaScript:isDelete("+scheduleForms[i].sformId+")' ><i class=\"fa fa-remove\"></i></a>\n" +
                       "                    </li>\n" +
                       "                </ul>\n" +
                       "            </div>\n" +
                       "        </div>\n" +
                       "    </div>\n" +
                       "</div>"

/*
                    form+="                <!--日程表一-->\n" +
                        "                <div class=\"layui-col-xs12 layui-col-sm6 layui-col-md3  \" id='abc"+i+"'>\n" +
                        "                    <div class=\"layui-card layui-height-lwh\" >\n" +
                        "                        <div class=\"layui-card-header layui-height-lwh-header\">\n" +
                        "                            <label>创建时间："+scheduleForms[i].creatTime+"</label>\n" +
                        "                            <button name=\"my_schedule_delete_1\" type=\"button\" class=\"layui-btn layui-btn-sm layui-btn-primary pull-right layui-color-skyblue-lwh-delete\">\n" +
                        "                                <i class=\"layui-icon\">&#xe640;</i>\n" +
                        "                            </button> \n" +
                        "                        </div>\n" +
                        "                        <div class=\"layui-card-body layui-height-lwh-body \">\n" +
                        "                            <p class=\"lay-big-font\">"+scheduleForms[i].sformName+"</p>\n" +
                        "                            <p>你好空格&nbsp;<span class=\"pull-right\">" +
                        "                           <input type=\"checkbox\" name=\"my_schedule_open_1\" lay-filter=\"myfirst_share\" " +
                        "                           id=\""+scheduleForms[i].sformId+"\" lay-skin=\"switch\" lay-text=\"公开|私有\" "+status+" ></span></p>\n" +
                        "                        </div>\n" +
                        "                    </div>\n" +
                        "                </div>"*/


                    sformStatus="checked";
                }




                for (var i=0;i<scheduleFrames.length;i++) {
                    var creatTime=createTime(scheduleFrames[i].creatTime);
                    if (scheduleFrames[i].publish!="on") {
                        sframeStatus="";
                        publish='true';

                    }

                    frame+="<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md3 \" id=\"show-btn\">\n" +
                        "    <div class=\"layui-card layui-height-lwh\" id=\"show1\">\n" +
                        "        <div class=\"box layui-card-background-lwho\">\n" +
                        "            <div class=\"box-content\">\n" +
                        "                <div class=\"layui-card-header layui-height-lwh-header\">\n" +
                        "                    <label>创建时间："+creatTime+"</label>\n" +
                        "                </div>\n" +
                        "                <div class=\"layui-card-body layui-height-lwh-body\">\n" +
                        "                    <p class=\"lay-big-font\">"+scheduleFrames[i].sframeName+"</p>\n" +
                        "                    <p><span class=\"pull-right\">\n" +
                        "                                                  <input type=\"checkbox\" name=\"my_schedule_open_1\" lay-filter=\"myfirst_share\"\n" +
                        "                                                         id='"+scheduleFrames[i].sframeId+" ' lay-skin='switch' lay-text=\"公开|私有\" "+sframeStatus+" ></span></p>\n" +
                        "                </div>\n" +
                        "                <ul class=\"icon\">\n" +
                        "                    <li>\n" +
                        "                        <a href='javaScript:copySframe("+scheduleFrames[i].sframeId+")' ><i class=\"fa fa-copy\"></i></a>\n" +
                        "                    </li>\n" +
                        "                    <li>\n" +
                        "                        <a href='javaScript:reviseSframe("+scheduleFrames[i].sframeId+","+publish+")' ><i class=\"fa fa-magic\"></i></a>\n" +
                        "                    </li>\n" +
                        "                    <li>\n" +
                        "                        <a href='javaScript:deleteSframe("+scheduleFrames[i].sframeId+")' ><i class=\"fa fa-remove\"></i></a>\n" +
                        "                    </li>\n" +
                        "                </ul>\n" +
                        "            </div>\n" +
                        "        </div>\n" +
                        "    </div>\n" +
                        "</div>"

/*
                    frame+="                <!--日程框架一-->\n" +
                        "                <div class=\"layui-col-xs12 layui-col-sm6 layui-col-md3 \">\n" +
                        "                    <div class=\"layui-card layui-height-lwh\">\n" +
                        "                        <div class=\"layui-card-header layui-height-lwh-header\">\n" +
                        "                            <label>创建时间："+schedleFrames[i].creatTime+"</label>\n" +
                        "                            <button name=\"my_schedule_delete_1\" type=\"button\" class=\"layui-btn layui-btn-sm layui-btn-primary pull-right layui-color-skyblue-lwh-delete\">\n" +
                        "                                <i class=\"layui-icon\">&#xe640;</i>\n" +
                        "                            </button>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"layui-card-body layui-height-lwh-body \">\n" +
                        "                            <p class=\"lay-big-font\">"+schedleFrames[i].sframeName+"</p>\n" +
                        "                            <p>dgdabdfbadfb&nbsp;<span class=\"pull-right\">" +
                        "                           <input type=\"checkbox\" name=\"schedule_frame_open_2\" lay-filter=\"myfirst_share\"" +
                        "                            id='"+schedleFrames[i].sframeId+"' lay-skin=\"switch\" lay-text=\"公开|私有\" checked></span></p>\n" +
                        "                        </div>\n" +
                        "                    </div>\n" +
                        "                </div>"*/
                    sframeStatus="checked";
                    publish='off';
                }



                $("#showsfrom").html(form);
                $("#showsframe").html(frame);

                for (var i=0;i<scheduleFormItems.length;i++){
                    var sformItemDate=createTime(scheduleFormItems[i].sformItemDate).split(" ")[0];
                    var startTime=createTime(scheduleFormItems[i].startTime);
                   var stopTime= createTime(scheduleFormItems[i].stopTime);

                    sformItemHtml+="<ul class=\"layui-timeline\">\n" +
                        "                                <li class=\"layui-timeline-item\">\n" +
                        "                                    <i class=\"layui-icon layui-timeline-axis\">&#xe63f;</i>\n" +
                        "                                    <div class=\"layui-timeline-content layui-text\">\n" +
                        "                                        <h3 class=\"layui-timeline-title\">\n" +
                        "                                            "+scheduleFormItems[i].sformItemName+"\n" +
                        "                                            <small>"+scheduleFormItems[i].location+"</small>&emsp;\n" +
                        "                                            <span class=\"layui-badge-rim\">"+sformItemDate+"</span>\n" +
                        "                                        </h3>\n" +
                        "                                        <ul>\n" +
                        "                                            <li class=\"text-danger\">备注："+scheduleFormItems[i].comment+"</li>\n" +
                        "                                            <li class=\"text-danger\">开始时间："+startTime+"</li>\n" +
                        "                                            <li class=\"text-danger\">结束时间："+stopTime+"</li>\n" +
                        "                                        </ul>\n" +
                        "                                    </div>\n" +
                        "                                </li>\n" +
                        "                            </ul>\n" +
                        "\n";

                }

                $("#sformItemMess").append(sformItemHtml);
                layui.use('form', function() {
                    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
                    form.render();
                });
            }
        });


    });


/*    $('#cancel,#cancel2,#cancel3,#cancel4').on('click', function(){
        var othis = $(this);
        layer.open({
            content: '您确认取消认购？',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function(){
                layer.open({content: '确认取消认购', time: 1});
                othis.parents('.atxt').remove();
            }, no: function(){
                layer.open({content: '您选择了取消', time: 1});
            }
        });
    });*/


    form.on('#remove',function () {
        var othis = $(this);
        layer.confirm('您是确定要删除该日程表吗？', {
                btn: ['确定','取消'] //按钮
            },
            function(){
                layer.msg('确定', {icon: 1});
                $.post({
                    url:"/myScheduleForm/deleteSformBySformId?sformId="+$("#selectId").valueOf(),
                    success:function (data) {
                        console.log(data);
                        if (data.valueOf()=='删除日程表成功！') {
                            Feng.success(data.valueOf()+"正跳转到日程表页面");
                            /*   /!*!//关闭当前窗口*/
                            admin.closeThisDialog();
                            parent.location.href="/myScheduleForm/showScheduleForm";

                        }else {
                            Feng.error(data.valueOf());
                        }
                    }
                });

            });

    });


/*
    //共享或者不共享
    form.on('switch(myfirst_share)', function(data){
        alert("ASgG")
        if (data.elem.checked){
            layer.msg(data.elem.id,{time:5000});
            alert(data.value)
        };
        var sformId=data.elem.id;
        var status=data.elem.checked;
        $.ajax({
            url:"/myScheduleForm/setShare?sformId="+sformId+"&status="+status,
            type:"get",
            dataType:"json",
            success:function(data){
                console.log(data);
                layer.msg(data.msg);
            },
            error:function(data){
                $.messager.alert('错误',data.msg);
            }
        });
        // layer.close(index);
    });

    */

    });


